"""author: songzhiqiang
   data: 2021/12/10
   project: zuoye2
"""


# 使用面向对象做一个ATM（存取款功能）
# ATM类
#  属性： 钱，区域
#  方法：（存取）
#      用户可以过来取钱
#      取了钱ATM的钱就会减少
#      用户的账户的钱也会减少
# 用户类
#  属性：用户名，  密码， 账户金额
# 要求：
#    菜单   有登陆验证

class ATM():
    ATMmoney = 500000
    usermoney = 0
    locate = "changsha"

    def draw(self, drawmoney):
        if drawmoney <= self.ATMmoney and drawmoney <= self.usermoney:
            self.ATMmoney -= drawmoney
            self.usermoney -= drawmoney
        else:
            print('余额不足,不能取出')
        print(f"剩余{self.usermoney}元")

    def save(self, savemoney):
        self.usermoney += savemoney
        print(f"账户余额{self.usermoney}元")


class User():
    user_dict = {"root": {'passwd': 123456, "money": 30000}}

    def useradd(self, username, passwd,money):
        if username in self.user_dict:
            return 0
        else:
            self.user_dict[username] = {passwd,money}
            return 1

    def userlogin(self, username, passwd):
        if username and self.user_dict[username] == passwd:
            return 1
        else:
            return 0


def menu():
    print("欢迎来到ATM".center(50, '*'))
    print("""
请输入您要执行的操作：
    1.注册
    2.登录
    3.存款
    4.取钱
    5.退出系统
    """)
    print("*" * 55, '\n')


menu()
a = ATM()

b = User()

while 1:
    input_num = int(input())
    if input_num == 1:
        username = input("请输入要注册的用户名：")
        passwd = int(input("请输入密码："))
        if b.useradd(username, passwd,money=11111000):
            print("用户创建成功")
            print(b.user_dict)
        else:
            print("用户已存在")

    if input_num == 2:
        username = input("请输入用户名：")
        passwd = int(input("请输入密码："))
        if b.userlogin(username, passwd):
            print("登录成功")
        else:
            print("登录失败")

    elif input_num == 3:
        save_money = int(input("请输入存款金额："))
        a.save(save_money)

    elif input_num == 4:
        draw_money = int(input("请输入取款金额："))
        a.draw(draw_money)
    else:
        break
